package com.wpf.alarm_clock;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
// 闹钟
public class Login {
    static Scanner sc = new Scanner(System.in);
    static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) throws InterruptedException {
//        LocalDateTime xiang_time = enter1();
        LocalDateTime xiang_time = enter2();
        isXiang(xiang_time);

    }

    private static void isXiang(LocalDateTime xiangTime) throws InterruptedException {
        LocalDateTime now =LocalDateTime.now();
        do{
            now = LocalDateTime.now();
            System.out.println("当前时间是："+LocalDateTime.now().format(formatter));
            Thread.sleep(1000);
        }while (xiangTime.isAfter(now));

        // 跳出循环说明响铃时间在当前时间之后了，所以可以跳出循环了
        System.out.println("响铃了");
    }

//    第一种方案：用户输入完整的年月日时分秒，然后响铃
//    第二种方案：用户设置多少分钟后响铃：
    public static LocalDateTime enter1() {
        System.out.println("格式为：2024-04-05 18:18:18");
        System.out.println("请输入要响铃的时间:");
        // 这里一定是要nextLing() 要接收一整行的数据，否则会以空格截断
//        String str = sc.nextLine();
        String str = "2024-11-16 10:26:40";
        return format_time(str);
    }


    public static LocalDateTime enter2() {
        System.out.println("请输入要多少分钟后响铃【直接输入分钟数即可】:");
        int numbs = sc.nextInt();
        return format_time(numbs);

    }

    public static LocalDateTime format_time(String str) {
        LocalDateTime ldt = LocalDateTime.parse(str, formatter);
        return ldt;
    }
    public static LocalDateTime format_time(int nums) {
        LocalDateTime now =LocalDateTime.now();
        LocalDateTime ldt = now.plusMinutes(nums);
        return ldt;
    }


}
